#ifndef _BUOLA_WIDGETS_CFILELIST_H_
#define _BUOLA_WIDGETS_CFILELIST_H_

#include <buola/utility/uevent.h>

#include <buola/widgets/clistbox.h>
#include <buola/io/curi.h>
#include <buola/io/cfolder.h>

namespace buola { namespace gui {

class CFileListFiller;
    
class CFileList : public CListBox
{
public:
    CFileList();
    ~CFileList();

    void SetFilter(io::PFileFilter);

    void SetURI(const io::CURI&);
    void ChangeURI(const io::CURI&);

    io::CURI GetURI(CListBox::SItem*);

    io::CFile GetSelectedFile();

    void CreateFolder(const std::wstring &pName=std::wstring());

protected:
    io::CFile GetFile(CListBox::SItem*);

protected:
    void FillList();

public:
//////////////// Event handling ////////////////
    virtual void OnFillMenu(gui::PMenu,bool);

    virtual void OnDragDrag(gui::CDrag*,gui::CClipboard*);
    virtual void OnItemRemoved(CListBox::SItem*);
    virtual void OnItemDblClk(CListBox::SItem*);
    virtual void OnItemChanged(CListBox::SItem*);

    void OnIntAction(TID pAction,const io::CFile &pFile);
    void OnFillerAdd(int pCount,CListBox::SItem **pItems,bool pCreatingLater,TID pID);
    void OnFillerRemove(const std::wstring &pName,TID pID);

////////////////// Data
public:
    USignal<void(const io::CFile&)> sFillActions;
    USignal<void(TID,const io::CURI&)> sExtAction;
    UEvent<void(TID,io::CURI)> eIntAction;

protected:
    io::PFileFilter mFilter;
    io::CFolder mFolder;
    io::CURI mURI;

    CFileListFiller *mFiller;
    TID mFillerID;

    CListBox::SItem *mCreatingFolderItem;

    friend class CFileListFiller;
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
